import Mock from "mockjs"
import { param2Obj } from '../utils/url';

let List =[]
for(var i=0;i<200;i++){
    List.push({
          id:Mock.mock('@zip'),
          userwechat: Mock.mock('@first'),
          phoneNum:'13888888888',
          courseName:'幼儿英语入门课程',
          orderAmount:'2399.00',
          orderState:Mock.mock('@integer(0, 3)'), //0 待支付  1 已关闭 2 待确认 3 已完成
          date:Mock.mock('@datetime')
    })
}





export default {
    getHomeData:(config)=>{
        console.log('config',param2Obj(config.url));
        let { search,page,pageSize,value1,value2 } = param2Obj(config.url)
        console.log(config.url);
console.log(value1);
        let newList= List.filter(item=>{
            return item.userwechat.indexOf(search) != -1
        })
     
            if(value1 && value2 && value1<value2 ){
                newList= List.filter(item=>{
                    return item.date>value1 && item.date< value2
                })
            }
          //分页  (page-1)  * pageSize <= index <  page  * pageSize
        let newList2 = newList.filter((item,index)=>{
            return (page-1)  * pageSize <= index && index  <  page  * pageSize
        })
        

        return {
            code:200,
            msg:'请求成功',
            data:newList2,
            total:List.length
        }
    },
    deleteMockData:config=>{
        console.log('config',config);
        let { id } =JSON.parse(config.body)
        let newList = List.filter(item=>{
            return item.id !=id
        })
        List = newList
        return{
            code:200,
            msg:'取消成功',
            data:null
        }
    },
    batchDeleteMockData:(config)=>{
        let { ids } =JSON.parse(config.body)
         let newList =  List.filter(item=>{
            return ids.indexOf(item.id) === -1
        })
        List = newList
        return{
            code:200,
            msg:'批量取消成功',
            data:null
        }
    },
    lookMockData:(config)=>{
        let id =config.body
        let a={}
        List.forEach((r,i)=>{
            if(r.id == id){
                a =r
            }
        })
        return{
            code:200,
            msg:'查看成功',
            data:a
        }
    },
}